package dao

import "2302a/tiktok_business/global"

func Create[T any](data *T) bool {

	if err := global.DB.Create(data).Error; err != nil {
		return false
	}
	return true
}
func Delete[T any](data *T) bool {

	if err := global.DB.Delete(data).Error; err != nil {
		return false
	}
	return true
}
func Updates[T any](data *T) bool {

	if err := global.DB.Updates(data).Error; err != nil {
		return false
	}
	return true
}
func GetOneById[T any](id uint, data *T) bool {

	if err := global.DB.Where("id = ?", id).Find(data).Limit(1).Error; err != nil {
		return false
	}
	return true
}
func GetOneByField[T any](where *T, data *T) bool {

	if err := global.DB.Where(where).Find(data).Limit(1).Error; err != nil {
		return false
	}
	return true
}
func GetListByField[T any](where *T, data *[]T) bool {

	if err := global.DB.Where(where).Find(data).Error; err != nil {
		return false
	}
	return true
}
